package cmd

import (
	"fmt"
	"github.com/spf13/cobra"
	"strings"
)

const (
	Upper = iota + 1
	Lower
)

var str string
var mode int

var wordCmd = &cobra.Command{
	Use:        "word",
	Aliases:    nil,
	SuggestFor: nil,
	Short:      "单词格式化",
	Long:       `单词格式化`,
	Version:    "1.0",
	Run: func(cmd *cobra.Command, args []string) {
		switch mode {
		case Lower:
			fmt.Printf("%s", strings.ToLower(str))
		case Upper:
			fmt.Printf("%s", strings.ToUpper(str))
		}
	},
}

func init() {
	wordCmd.Flags().StringVarP(&str, "str", "s", "", "待转换字符串")
	wordCmd.Flags().IntVarP(&mode, "mode", "m", 0,
		`转换模式
1 - 全部转成大写
2 - 全部转成小写
`)
	rootCmd.AddCommand(wordCmd)
}
